package com.xyht.sca_s.student_manage_system.modules.mailbox.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.mailbox.entity.SmsMailbox;
import com.xyht.sca_s.student_manage_system.modules.mailbox.entity.dto.SmsReplyMailboxDto;
import com.xyht.sca_s.student_manage_system.modules.mailbox.entity.dto.SmsSendMailboxDto;
import com.xyht.sca_s.student_manage_system.modules.mailbox.service.SmsMailboxService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2022-12-26
 */
@RestController
@RequestMapping("/mailbox")
@SecretBody
public class SmsMailboxController {

    @Resource
    private SmsMailboxService smsMailboxService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("发送信箱模块")
    @PostMapping("/student/add")
    public ResponseResult addMailbox(@RequestBody SmsSendMailboxDto smsSendMailboxDto, HttpServletRequest request){
        String sender = jwtTokenUtil.getUserIdByRequest(request);
        return smsMailboxService.addMailbox(smsSendMailboxDto,sender);
    }

    @ApiModelProperty("查看我的信箱模块")
    @GetMapping("/student/my")
    public ResponseResult selectMyAllMailbox(HttpServletRequest request,
                                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                           @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        String sender = jwtTokenUtil.getUserIdByRequest(request);
        return smsMailboxService.selectMyAllMailbox(sender,pageSize,pageNum);
    }

    @ApiModelProperty("查看信箱的详情模块")
    @GetMapping("/id")
    public ResponseResult selectMailboxById(String id){
        return smsMailboxService.selectMailboxById(id);
    }

    @ApiModelProperty("查看公开的信箱模块")
    @GetMapping("/student/open")
    public ResponseResult selectAllOpenMailbox(HttpServletRequest request,
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        String sender = jwtTokenUtil.getUserIdByRequest(request);
        return smsMailboxService.selectAllOpenMailbox(sender,pageSize,pageNum);
    }

    @ApiModelProperty("教师端查看所有信箱模块")
    @GetMapping("/teacher/all")
    public ResponseResult selectAllMailbox(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                           @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return smsMailboxService.selectAllMailbox(pageSize,pageNum);
    }

    @ApiModelProperty("教师端删除单个信箱模块")
    @PostMapping("/teacher/delete")
    public ResponseResult deleteMailbox(@RequestBody SmsMailbox smsMailbox){
        return smsMailboxService.deleteMailboxById(smsMailbox);
    }

    @ApiModelProperty("教师端回复信箱模块")
    @PostMapping("/teacher/update")
    public ResponseResult ReplyMailbox(@RequestBody SmsReplyMailboxDto smsReplyMailboxDto){
        return smsMailboxService.addReplyMailbox(smsReplyMailboxDto);
    }

    @ApiModelProperty("搜索公开接口")
    @GetMapping("/student/selectOpen")
    public ResponseResult selectOpenMailbox(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "title",required = false) String title){
        return smsMailboxService.selectOpenMailbox(pageSize,pageNum,title);
    }

    @ApiModelProperty("搜索我的接口")
    @GetMapping("/student/selectMy")
    public ResponseResult selectMyMailbox(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          HttpServletRequest request,String title){
        String sender = jwtTokenUtil.getUserIdByRequest(request);
        return smsMailboxService.selectMyMailbox(pageSize,pageNum,title,sender);
    }

    @ApiModelProperty("后端信箱公开切换")
    @PostMapping("/teacher/switchIsOpen")
    public ResponseResult switchIsOpen(@RequestBody SmsMailbox smsMailbox,HttpServletRequest request){
        String sender = jwtTokenUtil.getUserIdByRequest(request);
        return smsMailboxService.switchIsOpen(smsMailbox,sender);
    }
}

